package com.example.wwww.controller;

import com.example.wwww.model.Merchant;
import com.example.wwww.repo.InMemoryStore;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/merchants")
public class MerchantController {
    private final InMemoryStore store;
    public MerchantController(InMemoryStore store) { this.store = store; }

    @GetMapping
    public List<Merchant> list() { return store.getMerchants(); }

    @GetMapping("/{id}")
    public ResponseEntity<Merchant> get(@PathVariable Long id) {
        return store.getMerchantById(id).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
    }
}


